package com.xiaoshuidi.cloud.module.rooms.enums;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author Feng
 * @date 2023/4/27
 * 资产所属方
 */
@AllArgsConstructor
@Getter
public enum EquipmentOwn {
    COMPANY(1, "公司"),
    LANDLORD(2, "业主");


    private int code;
    private String name;

    public static String getNameByCode(String code) {
        if (StrUtil.isEmpty(code)) {
            return null;
        }
        Optional<EquipmentOwn> find = Arrays.stream(EquipmentOwn.values()).filter(s -> (s.getCode() + "").equals(code)).findFirst();
        if (find.isPresent()) {
            return find.get().getName();
        }
        return null;
    }

    public static int getCodeByName(String name) {
        EquipmentOwn equipmentOwn = Arrays.stream(EquipmentOwn.values()).filter(p -> p.name.equals(name)).findFirst().orElse(null);
        Assert.isTrue(equipmentOwn != null, "EquipmentOwn类型:{}不存在", name);
        return equipmentOwn.getCode();
    }
}
